package p270jp.pxv.android.model;

import android.content.Context;
import java.util.ArrayList;
import java.util.Iterator;
import p056bp.LocalDate;
import p115dp.DateTimeFormatter;
import p270jp.pxv.android.legacy.constant.SearchDuration;
import p325m0.MutabilityOwnership;
import p436q6.StringMerger;
import p629xm.Iterators;
import p629xm._Arrays;

/* compiled from: SearchDurationListConverter.kt */
/* renamed from: jp.pxv.android.model.SearchDurationListConverter */
/* loaded from: classes2.dex */
public final class SearchDurationListConverter {
    public static final int $stable = 8;
    private final Context context;

    public SearchDurationListConverter(Context context) {
        MutabilityOwnership.m3745m(context, "context");
        this.context = context;
    }

    private final String createCustomDurationLabel(SearchDurationSetting searchDurationSetting) {
        LocalDate startDate = searchDurationSetting.getStartDate();
        if (startDate != null) {
            LocalDate endDate = searchDurationSetting.getEndDate();
            if (endDate != null) {
                Context context = this.context;
                int titleResId = SearchDuration.CUSTOM_DURATION.getTitleResId();
                DateTimeFormatter bVar = DateTimeFormatter.f12353h;
                String string = context.getString(titleResId, startDate.m10107G(bVar), endDate.m10107G(bVar));
                MutabilityOwnership.m3746l(string, "context.getString(\n     …ISO_LOCAL_DATE)\n        )");
                return string;
            }
            throw new IllegalArgumentException("Required value was null.".toString());
        }
        throw new IllegalArgumentException("Required value was null.".toString());
    }

    public final String createItemLabel(SearchDurationParameter searchDurationParameter) {
        MutabilityOwnership.m3745m(searchDurationParameter, "searchDurationParameter");
        if (searchDurationParameter.isCustomSetting()) {
            SearchDurationSetting customDurationSetting = searchDurationParameter.getCustomDurationSetting();
            if (customDurationSetting != null) {
                return createCustomDurationLabel(customDurationSetting);
            }
            throw new IllegalArgumentException("Required value was null.".toString());
        }
        String string = this.context.getString(searchDurationParameter.getSearchDuration().getTitleResId());
        MutabilityOwnership.m3746l(string, "context.getString(searchDuration.titleResId)");
        return string;
    }

    public final ArrayList<SingleChoiceListValue> createSingleChoiceListValues(SearchDurationParameter searchDurationParameter) {
        MutabilityOwnership.m3745m(searchDurationParameter, "durationParameter");
        ArrayList<SingleChoiceListValue> arrayList = new ArrayList<>();
        if (searchDurationParameter.isCustomSetting()) {
            SearchDurationSetting customDurationSetting = searchDurationParameter.getCustomDurationSetting();
            if (customDurationSetting != null) {
                arrayList.add(new SingleChoiceListValue(0, createCustomDurationLabel(customDurationSetting)));
            } else {
                throw new IllegalArgumentException("Required value was null.".toString());
            }
        }
        SearchDuration[] values = SearchDuration.values();
        Iterator<Integer> it = StringMerger.m2840v(1, values.length).iterator();
        while (it.hasNext()) {
            int c = ((Iterators) it).mo677c();
            arrayList.add(new SingleChoiceListValue(c, this.context.getString(values[c].getTitleResId())));
        }
        return arrayList;
    }

    public final int getIndex(SearchDuration searchDuration) {
        MutabilityOwnership.m3745m(searchDuration, "searchDuration");
        SearchDuration[] values = SearchDuration.values();
        Iterator<Integer> it = _Arrays.m713H(values).iterator();
        while (it.hasNext()) {
            int c = ((Iterators) it).mo677c();
            if (values[c] == searchDuration) {
                return c;
            }
        }
        throw new IllegalArgumentException();
    }
}
